<!--混凝土拌和站---动态监控--实时监控-->
<!--
 * @Author: 卡卡 1071780426@qq.com
 * @Date: 2022-12-02 13:13:25
 * @LastEditors: CNN 969682281@qq.com
 * @LastEditTime: 2024-01-19 16:35:30
 * @FilePath: \backstage - 副本\src\views\aa.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="department" id="department">
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav app-container-search">
        <!-- 左侧 -->
        <el-form ref="form" :model="getList" label-width="110px">
          <el-row :gutter="20">
            <el-col :span="6"
              ><el-form-item label="项目名称：">
                <el-select
                  class="selectBhz"
                  v-model="getList.fprojectid"
                  placeholder="所有项目"
                  @change="selectProject"
                >
                  <el-option
                    v-for="v in projectsObj"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="标段名称：">
                <el-select
                  class="selectBhz"
                  v-model="getList.fCompanyid"
                  placeholder="所有标段"
                  @change="selectTender"
                >
                  <el-option
                    v-for="v in tendersObj"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select> </el-form-item
            ></el-col>

            <el-col :span="6">
              <el-form-item label="所有拌和站：">
                <el-select
                  class="selectBhz"
                  v-model="getList.stationId"
                  placeholder="所有拌和站"
                  @change="selectStation"
                >
                  <el-option
                    v-for="v in bhzDataList"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="所有拌和机：">
                <el-select
                  class="selectBhz"
                  v-model="getList.machineId"
                  placeholder="所有拌和机"
                >
                  <el-option
                    v-for="v in bhjDataList"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="6">
              <el-form-item label="出料时间：">
                <el-date-picker
                  :picker-options="pickerOptions"
                  value-format="yyyy-MM-dd"
                  @change="selectTime"
                  v-model="timeDuring"
                  type="daterange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6"
              ><el-form-item label="强度等级：">
                <el-select
                  class="selectBhz"
                  v-model="getList.strengthgrade"
                  placeholder="强度等级"
                >
                  <el-option
                    v-for="v in strengthGradeDataList"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="预警等级：">
                <el-select
                  class="selectBhz"
                  v-model="getList.warningLevel"
                  placeholder="预警等级"
                >
                  <el-option
                    v-for="v in djDataList"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="闭合状态：">
                <el-select
                  class="selectBhz"
                  v-model="getList.fCloseoperation"
                  placeholder="闭合状态"
                >
                  <el-option
                    v-for="v in CloseoperationDataList"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select> </el-form-item
            ></el-col>
          </el-row>
          <div class="searchBtn">
            <el-button
              type="primary"
              :loading="editLoading"
              @click="yj_searchForm(getList)"
              >查询</el-button
            >
            <el-button @click="reset">重置</el-button>
          </div>
        </el-form>
        <!-- 左侧 -->
      </div>
      <!-- <div class="app-container-btn ">
        <el-button type="primary" @click="yj_viewForm">查看</el-button>
      </div> -->
      <!-- 表格 -->
      <div class="text_table TensionRealTime">
        <tableData
          :stripe="false"
          height="100%"
          :config="table_config"
          :dataList="tableData"
          :loading="listLoading"
          @click-change="rowChange"
          @openDialog="yj_viewForm"
          :page="getList.page"
          :pageSize="getList.pageSize"
        />
        <pagination
          :info="queryCriteriaData"
          :total="queryCriteriaData.total"
          :pageNum.sync="getList.page"
          :limit.sync="getList.pageSize"
          @pagination="yj_searchForm(getList)"
        />
      </div>
    </div>
    <messageBox
      :showMsgBox="showMsgBox"
      :msgTip="msgTip"
      :msgType="msgType"
      @confirmMsg="confirmMsg"
    ></messageBox>
  </div>
</template>
  
<script>
import messageBox from "@/components/public/messageBox"; //主页面分页
import actions from "@/actions";
import TableData from "@/components/public/el-tables"; //主页面列表
import Pagination from "@/components/public/el-pagination"; //主页面分页
import formJs from "./regexDetail.js"; //新增弹框配置项
import {
  getClosedLists, //主页面列表接口
  getStationmachineList, //拌合站列表
  getMachineListByStationId, //拌合机
} from "@/api/request.js";
import { statusType2 } from "@/utils/config"; //配置项
export default {
  name: "closure",
  data() {
    return {
      name: "closure", //按钮配置页面代号
      editLoading: false,
      timeDuring: "",
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
      },
      showMsgBox: false,
      msgTip: "请先选中数据行！",
      msgType: 1,
      rowInfo: null, //当前行信息
      projectsObj: [], //项目名
      tendersObj: [],
      queryCriteriaData: {}, //分页
      strengthGradeDataList: formJs.strengthGradeDataList,
      djDataList: formJs.djDataList,
      CloseoperationDataList: formJs.CloseoperationDataList,
      level: [], //强度等级
      earlyWarning: [], //预警标准
      bhzDataList: [], //拌合站
      bhjDataList: [], //拌合机
      timeDuring: "", //主页面日期筛选绑定值
      // 列表配置项
      table_config: formJs.cbtable_config,
      tableData: [], //表格列表数据列表
      fId: null, //点击当前列表数据fId
      listLoading: false, //列表数据加载loading
      // 列表给后端传参
      getList: {
        fprojectid: "",
        fCompanyid: "", // 施工标段id
        startDates: "", // 开始时间
        endDates: "", // 截至时间
        strengthgrade: "", // 强度等级
        machineId: "", // 拌和机编号
        stationId: "", //拌合站
        keyWord: "", // 工程部位/工程名称 模糊条件
        page: 1, // 当前页码
        pageSize: 15, // 每页显示条数
        warningLevel: "", // 预警等级
        fCloseoperation: "", // 闭合状态
      },
      userInfo: {}, //登录用户
      token: null,
    };
  },
  components: {
    TableData, //主页面列表
    Pagination, //分页
    messageBox,
  },
  mounted() {
    actions.onGlobalStateChange((state, prev) => {
      this.userInfo = prev.currentUser;
      this.token = prev.token;
      var data = prev.currentUser.projects;
      this.projectsObj = [
        {
          fItemName: "所有项目",
          fItemValue: "",
        },
      ];
      data.map((item) => {
        this.projectsObj.push({
          fItemName: item.projectName,
          fItemValue: item.projectId,
        });
      });
    }, true);

    this.getDate();

    this.table_config.thead[6]["callback"] = function (rowData) {
      let data = statusType2[rowData.F_WarningLevel];
      if (data) {
        return data.label;
      }
    };
    this.table_config.thead[6]["specialClass"] = function (rowData) {
      let data = statusType2[rowData.F_WarningLevel];
      if (data) {
        return data.className;
      }
    };

    this.table_config.operation.cols = [
      {
        prop: "F_CloseOperation",
        type: "primary",
        handleRow: this.handleRow,
      },
    ];

    this.table_config.operation["specialClass"] = function (rowData) {
      var color = null;
      if (rowData == "未闭合") {
        color = "red !important";
      } else if (rowData == "已闭合") {
        color = "green !important";
      } else if (rowData == "无需闭合") {
        color = "#000 !important";
      } else {
        color = "#409eff !important";
      }
      return color;
    };
  },
  methods: {
    confirmMsg() {
      this.showMsgBox = false;
    },
    // 重置按钮
    reset() {
      this.timeDuring = "";
      this.getList = {
        fprojectid: "",
        fCompanyid: "", // 施工标段id
        startDates: "", // 开始时间
        endDates: "", // 截至时间
        strengthgrade: "", // 强度等级
        machineId: "", // 拌和机编号
        stationId: "", //拌合站
        keyWord: "", // 工程部位/工程名称 模糊条件
        page: 1, // 当前页码
        pageSize: 15, // 每页显示条数
        warningLevel: "", // 预警等级
        fCloseoperation: "", // 闭合状态
      };
    },
    selectProject(e) {
      this.tendersObj = [];
      this.getList.fCompanyid = "";
      this.getList.stationId = "";
      this.getList.machineId = "";
      this.bhzDataList = [];
      this.bhjDataList = [];
      if (e == "所有项目") {
        this.getList.fprojectid = "";
      } else {
        this.getTender(e, 1);
      }
    },
    async getTender(e, num) {
      await this.$http(
        " http://172.18.5.31:8300/IOTManagement/Base/Company/getGXJLBaseCompanyList.do?projectId=" +
          e,
        {
          headers: {
            "Content-Type": "application/json",
            Authorization: localStorage.getItem("access_token"),
          },
        }
      ).then((res) => {
        if (res.status == 200) {
          var data = res.data.data.GXCompanyList;
          this.tendersObj = [];
          if (data.length == 1) {
            data.map((item) => {
              this.tendersObj.push({
                fItemName: item.sectionName,
                fItemValue: item.sectionId,
              });
            });
            this.getList.fCompanyid = data[0].sectionId;
          } else {
            this.tendersObj = [
              {
                fItemName: "所有标段",
                fItemValue: "",
              },
            ];
            data.map((item) => {
              this.tendersObj.push({
                fItemName: item.sectionName,
                fItemValue: item.sectionId,
              });
            });
          }

          if (num == 0) {
            // num==0 调列表；num==1 不调
            this.yj_searchForm(this.getList);
          }
        }
      });
    },
    selectTender(e) {
      this.getList.stationId = "";
      this.getList.machineId = "";
      this.bhzDataList = [];
      this.bhjDataList = [];
      if (e == "所有标段") {
        this.getList.fCompanyid = "";
      } else {
        this.mixingPlantList(0, this.getList);
      }
    },
    selectStation(e) {
      this.getList.machineId = "";
      this.bhjDataList = [];
      if (e == "所有拌和站") {
        this.getList.stationId = "";
      } else {
        this.getbhjDataMethods(e, 4);
      }
    },
    btnRole(name) {
      // 按钮权限
      var btnList = [];
      var ModuleList = JSON.parse(
        sessionStorage.getItem("GxEmbedded_ModuleList")
      );
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        // this.yj_view = btnStr.includes("yj_view");
      } else {
        // this.yj_view = true;
      }
    },
    // 点击当前行
    rowChange(val) {
      return val;
    },
    // 获取列表数据
    yj_searchForm(data) {
      if (data.machineId == "所有拌和机") {
        data.machineId = "";
      }
      if (data.strengthgrade == "强度等级") {
        data.strengthgrade = "";
      }
      if (data.warningLevel == "预警级别") {
        data.warningLevel = "";
      }
      if (data.fCloseoperation == "闭合状态") {
        data.fCloseoperation = "";
      }
      this.listLoading = true;
      var id;
      if (data.fCompanyid != "") {
        id = data.fCompanyid;
      } else {
        id = data.fprojectid;
      }
      window.sessionStorage.setItem("GxEmbedded_getList", JSON.stringify(data));
      var getList = {
        fCompanyid: id, // 施工标段id，不为空
        startDates: data.startDates, // 开始时间
        endDates: data.endDates, // 截至时间
        strengthgrade: data.strengthgrade, // 强度等级
        stationId: data.stationId, // 梁场id
        machineId: data.machineId, // 压浆机id
        keyWord: data.keyWord, //  模糊条件
        page: data.page, // 当前页数
        pageSize: data.pageSize, // 每页显示条数
        warningLevel: data.warningLevel, // 预警等级
        fCloseoperation: data.fCloseoperation, // 闭合状态
      };

      getClosedLists(getList)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.listLoading = false;
            that.tableData = res.data.pageInfo.list;
            this.queryCriteriaData = res.data.pageInfo; //分页信息
            this.navigatepageNums =
              this.queryCriteriaData.navigatepageNums.length;
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 查看
    yj_viewForm(row) {
      // if (this.rowInfo != null) {
      this.$router.push({
        path: "/hntManage/closureDetail",
        query: {
          data: JSON.stringify(row),
        },
      });
      // } else {
      //   this.showMsgBox = true;
      // }
    },
    // 获取拌合站数据
    mixingPlantList(num, datas) {
      var data = {
        companyId: datas.fCompanyid, // 施工标段id
        modelType: num, // 类型
        stationType: "1", // 拌合站类型
      };

      // this.bhzDataList = [];
      getStationmachineList(data)
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;

            // if (num == 1) {
            //   this.bhjDataList = [
            //     {
            //       fItemName: "所有拌和机",
            //       fItemValue: "",
            //     },
            //   ];
            //   arr.map((item) => {
            //     this.bhjDataList.push({
            //       fItemName: item.fMachinename,
            //       fItemValue: item.fMachineid
            //     });
            //   });
            // } else
            // if (num == 0) {
            this.bhzDataList = [
              {
                fItemName: "所有拌和站",
                fItemValue: "",
              },
            ];

            arr.map((item) => {
              this.bhzDataList.push({
                fItemName: item.fMachinename,
                fItemValue: item.fMachineid,
              });
            });

            // }
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    getbhjDataMethods(data) {
      getMachineListByStationId({ stationId: data })
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;

            this.bhjDataList = [
              {
                fItemName: "所有拌和机",
                fItemValue: "",
              },
            ];
            arr.map((item) => {
              this.bhjDataList.push({
                fItemName: item.fMachinename,
                fItemValue: item.fMachineid,
              });
            });
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    selectTime(e) {
      if (e[0] != "" && e[1] != "") {
        this.getList.startDates = e[0] + " " + "00:00:00"; // 开始时间
        this.getList.endDates = e[1] + " " + "23:59:59"; // 截至时间
      } else {
        this.getList.startDates = ""; // 开始时间
        this.getList.endDates = ""; // 截至时间
      }
    },
    getDate() {
      if (JSON.parse(sessionStorage.getItem("GxEmbedded_getList"))) {
        this.getList = JSON.parse(sessionStorage.getItem("GxEmbedded_getList"));
        if (this.getList.fprojectid != "") {
          this.getTender(this.getList.fprojectid, 0);
        } else {
          this.getList.fprojectid = this.projectsObj[1].fItemValue;
          this.getTender(this.getList.fprojectid, 0);
        }
        if (this.getList.fCompanyid != "" && this.getList.fCompanyid != null) {
          this.mixingPlantList(0, this.getList);
        }

        if (this.getList.stationId != "" && this.getList.stationId != null) {
          this.getbhjDataMethods(this.getList.stationId);
        }

        if (this.getList.startDates == "" || this.getList.startDates == null) {
          this.getList.startDates = this.common.getDay(-90) + " " + "00:00:00"; // 开始时间
          this.getList.endDates = this.common.getDay(0) + " " + "23:59:59"; // 截至时间
        }
        this.timeDuring = [this.getList.startDates, this.getList.endDates];
      } else {
        this.getList.startDates = this.common.getDay(-90) + " " + "00:00:00"; // 开始时间
        this.getList.endDates = this.common.getDay(0) + " " + "23:59:59"; // 截至时间
        this.getList.fprojectid = this.projectsObj[1].fItemValue;
        this.getTender(this.getList.fprojectid, 0);
        this.timeDuring = [
          this.common.getDay(-90) + " " + "00:00:00",
          this.common.getDay(0) + " " + "23:59:59",
        ];
      }
    },
    selectionChange() {},
  },
};
</script>
  
<style scoped>
.TensionRealTime {
  height: 100%;
  display: flex;
  flex-direction: column;
}
</style>